package com.jessechanrui.template.skeleton.common.base;

import com.jessechanrui.template.skeleton.common.constant.BusinessStatusCode;
import com.jessechanrui.template.skeleton.common.constant.IStatusCode;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

/**
 * 异常基类
 * @author chenrui
 * @date 2024/1/29
 */
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
public class BaseException extends RuntimeException {
    /**
     * 异常码
     */
    private Integer code;
    /**
     * 异常信息
     */
    private String message;

    public BaseException(IStatusCode statusCode, String message) {
        super(message);
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public BaseException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    /**
     * 默认异常使用INTERNAL_FAILR状态码
     * @param message
     */
    public BaseException(String message) {
        super(message);
        this.code = BusinessStatusCode.INTERNAL_FAIL.getCode();
        this.message = BusinessStatusCode.INTERNAL_FAIL.getMessage();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}